package org.cfg;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import java.util.Date;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.tools.SK_String;
import com.xiaoleilu.hutool.util.StrUtil;
import com.sojoys.artifact.build.data.base.BaseCfg;
import java.util.List;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.ToolCopy;
import java.util.Map;
import org.interfaces.Refresher;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
/**
 * 商品
 */
public class CommodityCfg extends BaseCfg<CommodityCfg> {

	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "commodity";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "org.cfg.CommodityCfg"; 
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 17;
	/**
	 * 数据库源字段注释
	 */
	public static final String[] SOURCE_COLUMN_REMARKS = new String[]{"","商品名称","所属商店","格子编号","开启条件","开启值","自动刷新表达式","权重(随机商店生效)","限购","限购值","全服限购额外限制个人购买的数量","出售时间类型","出售时间","道具","价格类型","价格数量","描述",};
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","name","storeId","grid","openContType","openContVal","autoRefreshCorn","weight","limitType","limitVal","serLimit","sellTimeType","sellTime","goods","priceType","priceVal","des",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","name","storeId","grid","openContType","openContVal","autoRefreshCorn","weight","limitType","limitVal","serLimit","sellTimeType","sellTime","goods","priceType","priceVal","des",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,3373707,-1884271140,3181382,1920494070,754689253,-1063811084,-791592328,1744370069,1164649830,1340431163,1458235673,1197579583,98539350,-2125731805,-1176949480,99346,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"int","String","int","int","int","int","String","int","int","int","int","int","int[]","Map","int[]","int[]","String",};
	/**
	 * 字段引用类型
	 */
	public static final Class[] COLUMN_CLASSTYPES = new Class[]{Integer.class,String.class,Integer.class,Integer.class,Integer.class,Integer.class,String.class,Integer.class,Integer.class,Integer.class,Integer.class,Integer.class,int[].class,Map.class,int[].class,int[].class,String.class,};
	
	/**
	 * id
	 */
	private int id;
	
	/**
	 * 商品名称
	 */
	private String name;
	
	/**
	 * 所属商店
	 */
	private int storeId;
	
	/**
	 * 格子编号
	 */
	private int grid;
	
	/**
	 * 开启条件
	 */
	private int openContType;
	
	/**
	 * 开启值
	 */
	private int openContVal;
	
	/**
	 * 自动刷新表达式
	 */
	private String autoRefreshCorn;
	
	/**
	 * 权重(随机商店生效)
	 */
	private int weight;
	
	/**
	 * 限购
	 */
	private int limitType;
	
	/**
	 * 限购值
	 */
	private int limitVal;
	
	/**
	 * 全服限购额外限制个人购买的数量
	 */
	private int serLimit;
	
	/**
	 * 出售时间类型
	 */
	private int sellTimeType;
	
	/**
	 * 出售时间
	 */
	private int[] sellTime;
	
	/**
	 * 道具
	 */
	private Map goods;
	
	/**
	 * 价格类型
	 */
	private int[] priceType;
	
	/**
	 * 价格数量
	 */
	private int[] priceVal;
	
	/**
	 * 描述
	 */
	private String des;
	
	
	
	public static CommodityCfg builder() {
		CommodityCfg commodityCfg = new CommodityCfg();
		return commodityCfg;
	}
	
	/**
	 * id
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * 商品名称
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * 所属商店
	 */
	public int getStoreId() {
		return storeId;
	}
	
	/**
	 * 格子编号
	 */
	public int getGrid() {
		return grid;
	}
	
	/**
	 * 开启条件
	 */
	public int getOpenContType() {
		return openContType;
	}
	
	/**
	 * 开启值
	 */
	public int getOpenContVal() {
		return openContVal;
	}
	
	/**
	 * 自动刷新表达式
	 */
	public String getAutoRefreshCorn() {
		return autoRefreshCorn;
	}
	
	/**
	 * 权重(随机商店生效)
	 */
	public int getWeight() {
		return weight;
	}
	
	/**
	 * 限购
	 */
	public int getLimitType() {
		return limitType;
	}
	
	/**
	 * 限购值
	 */
	public int getLimitVal() {
		return limitVal;
	}
	
	/**
	 * 全服限购额外限制个人购买的数量
	 */
	public int getSerLimit() {
		return serLimit;
	}
	
	/**
	 * 出售时间类型
	 */
	public int getSellTimeType() {
		return sellTimeType;
	}
	
	/**
	 * 出售时间
	 */
	public int[] getSellTime() {
		return sellTime;
	}
	
	/**
	 * 道具
	 */
	public Map getGoods() {
		return goods;
	}
	
	/**
	 * 价格类型
	 */
	public int[] getPriceType() {
		return priceType;
	}
	
	/**
	 * 价格数量
	 */
	public int[] getPriceVal() {
		return priceVal;
	}
	
	/**
	 * 描述
	 */
	public String getDes() {
		return des;
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.name;
        values[2] = this.storeId;
        values[3] = this.grid;
        values[4] = this.openContType;
        values[5] = this.openContVal;
        values[6] = this.autoRefreshCorn;
        values[7] = this.weight;
        values[8] = this.limitType;
        values[9] = this.limitVal;
        values[10] = this.serLimit;
        values[11] = this.sellTimeType;
        values[12] = this.sellTime;
        values[13] = this.goods;
        values[14] = this.priceType;
        values[15] = this.priceVal;
        values[16] = this.des;
        return values;
	}
	
	protected CommodityCfg createColumeValues(Object[] vals) {
		this.id = (int)vals[0];
		this.name = (String)vals[1];
		this.storeId = (int)vals[2];
		this.grid = (int)vals[3];
		this.openContType = (int)vals[4];
		this.openContVal = (int)vals[5];
		this.autoRefreshCorn = (String)vals[6];
		this.weight = (int)vals[7];
		this.limitType = (int)vals[8];
		this.limitVal = (int)vals[9];
		this.serLimit = (int)vals[10];
		this.sellTimeType = (int)vals[11];
		this.sellTime = (int[])vals[12];
		this.goods = (Map)vals[13];
		this.priceType = (int[])vals[14];
		this.priceVal = (int[])vals[15];
		this.des = (String)vals[16];
		return this;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.name);
        map.put(keys[2], this.storeId);
        map.put(keys[3], this.grid);
        map.put(keys[4], this.openContType);
        map.put(keys[5], this.openContVal);
        map.put(keys[6], this.autoRefreshCorn);
        map.put(keys[7], this.weight);
        map.put(keys[8], this.limitType);
        map.put(keys[9], this.limitVal);
        map.put(keys[10], this.serLimit);
        map.put(keys[11], this.sellTimeType);
        map.put(keys[12], this.sellTime);
        map.put(keys[13], this.goods);
        map.put(keys[14], this.priceType);
        map.put(keys[15], this.priceVal);
        map.put(keys[16], this.des);
        return map;
    }
    
    protected CommodityCfg createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.name = (String)map.get(keys[1]);
   		this.storeId = (int)map.get(keys[2]);
   		this.grid = (int)map.get(keys[3]);
   		this.openContType = (int)map.get(keys[4]);
   		this.openContVal = (int)map.get(keys[5]);
   		this.autoRefreshCorn = (String)map.get(keys[6]);
   		this.weight = (int)map.get(keys[7]);
   		this.limitType = (int)map.get(keys[8]);
   		this.limitVal = (int)map.get(keys[9]);
   		this.serLimit = (int)map.get(keys[10]);
   		this.sellTimeType = (int)map.get(keys[11]);
   		this.sellTime = (int[])map.get(keys[12]);
   		this.goods = (Map)map.get(keys[13]);
   		this.priceType = (int[])map.get(keys[14]);
   		this.priceVal = (int[])map.get(keys[15]);
   		this.des = (String)map.get(keys[16]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.name);
        obj.put(keys[2], this.storeId);
        obj.put(keys[3], this.grid);
        obj.put(keys[4], this.openContType);
        obj.put(keys[5], this.openContVal);
        obj.put(keys[6], this.autoRefreshCorn);
        obj.put(keys[7], this.weight);
        obj.put(keys[8], this.limitType);
        obj.put(keys[9], this.limitVal);
        obj.put(keys[10], this.serLimit);
        obj.put(keys[11], this.sellTimeType);
        obj.put(keys[12], this.sellTime);
        obj.put(keys[13], this.goods);
        obj.put(keys[14], this.priceType);
        obj.put(keys[15], this.priceVal);
        obj.put(keys[16], this.des);
        return obj;
    }
    
    protected CommodityCfg createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.name = obj.getString(keys[1]);
	    this.storeId = obj.getIntValue(keys[2]);
	    this.grid = obj.getIntValue(keys[3]);
	    this.openContType = obj.getIntValue(keys[4]);
	    this.openContVal = obj.getIntValue(keys[5]);
	    this.autoRefreshCorn = obj.getString(keys[6]);
	    this.weight = obj.getIntValue(keys[7]);
	    this.limitType = obj.getIntValue(keys[8]);
	    this.limitVal = obj.getIntValue(keys[9]);
	    this.serLimit = obj.getIntValue(keys[10]);
	    this.sellTimeType = obj.getIntValue(keys[11]);
		this.sellTime = obj.getObject(keys[12],int[].class);
		this.goods = obj.getObject(keys[13],Map.class);
		this.priceType = obj.getObject(keys[14],int[].class);
		this.priceVal = obj.getObject(keys[15],int[].class);
	    this.des = obj.getString(keys[16]);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeString(this.name);
	    byteBuf.writeInt(this.storeId);
	    byteBuf.writeInt(this.grid);
	    byteBuf.writeInt(this.openContType);
	    byteBuf.writeInt(this.openContVal);
	    byteBuf.writeString(this.autoRefreshCorn);
	    byteBuf.writeInt(this.weight);
	    byteBuf.writeInt(this.limitType);
	    byteBuf.writeInt(this.limitVal);
	    byteBuf.writeInt(this.serLimit);
	    byteBuf.writeInt(this.sellTimeType);
	    byteBuf.writeObject(this.sellTime);
	    byteBuf.writeObject(this.goods);
	    byteBuf.writeObject(this.priceType);
	    byteBuf.writeObject(this.priceVal);
	    byteBuf.writeString(this.des);
    }
	
	protected CommodityCfg readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.name = byteBuf.readString(null);
	    this.storeId = byteBuf.readInt(null);
	    this.grid = byteBuf.readInt(null);
	    this.openContType = byteBuf.readInt(null);
	    this.openContVal = byteBuf.readInt(null);
	    this.autoRefreshCorn = byteBuf.readString(null);
	    this.weight = byteBuf.readInt(null);
	    this.limitType = byteBuf.readInt(null);
	    this.limitVal = byteBuf.readInt(null);
	    this.serLimit = byteBuf.readInt(null);
	    this.sellTimeType = byteBuf.readInt(null);
	    this.sellTime = byteBuf.readIntArray(null);
	    this.goods = (Map)byteBuf.readObject();
	    this.priceType = byteBuf.readIntArray(null);
	    this.priceVal = byteBuf.readIntArray(null);
	    this.des = byteBuf.readString(null);
	    return this;
	}
	
	public CommodityCfg deepCopy(){
		CommodityCfg commodityCfg = null;
		try {
			commodityCfg = (CommodityCfg) super.clone();
		    commodityCfg.sellTime = ToolCopy.copyObject(this.sellTime);
		    commodityCfg.goods = ToolCopy.copyObject(this.goods);
		    commodityCfg.priceType = ToolCopy.copyObject(this.priceType);
		    commodityCfg.priceVal = ToolCopy.copyObject(this.priceVal);
			return commodityCfg;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return commodityCfg;
	}
//自定义内容起始位置
	private Date nextRefreshDate;
	private Date lastRefreshDate;
	// 上架时间
	private Date addedTime;
	// 下架时间
	private Date shelfTime;
	// 是否是动态配置
	private boolean dynamic;

	public Date getAddedTime() {
		return addedTime;
	}

	public void setAddedTime(Date addedTime) {
		this.addedTime = addedTime;
	}

	public Date getShelfTime() {
		return shelfTime;
	}

	public void setShelfTime(Date shelfTime) {
		this.shelfTime = shelfTime;
	}

	public boolean isDynamic() {
		return dynamic;
	}

	public void setDynamic(boolean dynamic) {
		this.dynamic = dynamic;
	}

	public Date getNextRefreshDate() {
		return nextRefreshDate;
	}

	public void setNextRefreshDate(Date nextRefreshDate) {
		this.nextRefreshDate = nextRefreshDate;
	}

	public Date getLastRefreshDate() {
		return lastRefreshDate;
	}

	public void setLastRefreshDate(Date lastRefreshDate) {
		this.lastRefreshDate = lastRefreshDate;
	}

	public class CommodityRefresher implements Refresher {
		@Override
		public Date getNextRefreshDate() {
			return nextRefreshDate;
		}

		@Override
		public void setNextRefreshDate(Date date) {
			nextRefreshDate = date;
		}

		@Override
		public Date getLastRefreshDate() {
			return lastRefreshDate;
		}

		@Override
		public void setLastRefreshDate(Date date) {
			lastRefreshDate = date;
		}
	}

//自定义内容结束位置
}
